package com.tjsinfo.tjsoa.doc.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.doc.bo.ITDocDocBO;
import com.tjsinfo.tjsoa.doc.bo.ITDocDocOpeBO;

public class DocDelAction extends Action {
	private ITDocDocBO docBo;
	private ITDocDocOpeBO docOpeBo;
	
	public void setDocBo(ITDocDocBO docBo) {
		this.docBo = docBo;
	}
	public void setDocOpeBo(ITDocDocOpeBO docOpeBo) {
		this.docOpeBo = docOpeBo;
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {	
			String id = request.getParameter("id");
			Integer docMark = Integer.parseInt(request.getParameter("docMark"));
			
			String linkurl = null;
			String message = null;
			switch (docMark) {
			case 0:
				linkurl = "doc/ori/oriList.jsp";
				message = "doc.oriDel.message";
				break;
			case 1:
				linkurl = "doc/cer/cerList.jsp";
				message = "doc.cerDel.message";
				break;
			case 2:
				linkurl = "doc/copy/copyList.jsp";
				message = "doc.copyDel.message";
				break;				
			}

			docBo.delete(id);
			docOpeBo.deleteA(id);
			
			request.setAttribute("linkurl", linkurl);
			request.setAttribute("message", message);	
			
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}

}
